@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">管理员管理</a>
        </div>
        <!-- cur-position end -->

        <div class="filter-box clearfix">
            <div class="fr">
                <a class="addBtn" href="{{route('Admin.Home.rechargePackageSet')}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>套餐名称</th>
                    <th>套餐金额</th>
                    <th>阅读币数量</th>
                    <th>赠送的阅读币数量</th>
                    <th>备注</th>
                    <th>排序</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($rechargePackages) > 0)
                    @foreach($rechargePackages as $a)
                        <tr id="rechargePackage_{{$a->id}}">
                            <td>{{$a->id}}</td>
                            <td>{{$a->name}}</td>
                            <td>{{$a->amount_money}}</td>
                            <td>{{$a->books_coin}}</td>
                            <td>{{$a->gift_books_coin}}</td>
                            <td>{{$a->remark}}</td>
                            <td>{{$a->sort}}</td>
                            <td>
                                @if($a->status == 0)
                                    <p style="color: red;">下架</p>
                                @else
                                    <p style="color: green;">上架</p>
                                @endif
                            </td>
                            <td>
                                <a class="color2" href="{{route('Admin.Home.rechargePackageSet')}}?id={{$a->id}}">编辑</a><span> | </span>
                                <a href="javascript:void(0);" class="del" data-id="{{$a->id}}">删除</a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
            <?php echo $rechargePackages->render(); ?>
        </div>
    </div>
    <script>
        $(function(){

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");
                $.ajax({
                    url:'{{route("Api.Admin.sys.delRechargePackage")}}',
                    type:'post',
                    dataType:'json',
                    data:{id:id},
                    success:function(obj) {
                        if (obj.level == "success") {
                            $("#rechargePackage_" + id).hide('slow');
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});

                        }
                    },
                    error:function(obj){
                        console.log(obj);
                    }

                });
            });
        });
    </script>
    <!-- content end -->

@endsection